﻿@using QuestionsAnswers.UI.Models
@model IEnumerable<QuestionsAnswers.UI.Models.Question>
@if (Model.Any())
{
    <table>
        <tr>
            <th>
                Rating
            </th>
            <th>
                Text
            </th>
            <th>
                User
            </th>
            <th>
                Answers
            </th>
            <th>
                Date Created
            </th>
            <th>
            </th>
        </tr>
        @foreach (var item in Model)
        { 
           
            <tr>
                <td>@Html.Partial("RatingsPartial", new RateModel { Id = item.QuestionId, Type = "Question", ReturnUrl = Request.Url.ToString(), Rating = item.QuestionRating })
                </td>
                <td>
                    @Html.ActionLink(item.Text, "Index", "Answer", new { id = item.QuestionId }, "")
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.User.UserName)
                </td>
                <td>
                    @Html.ActionLink(item.Answers.Count.ToString(), "Index", "Answer", new { id = item.QuestionId }, null)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.DateCreated)
                </td>
                <td>
                    @if (User.Identity.Name == item.User.UserName)
                    {
                        @Ajax.ActionLink("Edit", "Edit", "Question", new { id = item.QuestionId }, new AjaxOptions { OnSuccess = "OnSuccessCreate" })             
                        @:|
                       @Html.ConfirmLink("Delete", "Question", "Delete", new { id = item.QuestionId }, "Really Delete?")                
                        @:|
                                        }
                    @Html.ActionLink("Assign To Course/Users", "ModifyCourseUsers", "Question", new { id = item.QuestionId }, null)
                </td>
            </tr>
            <tr>
                <td colspan="10">
                    <hr />
                </td>
            </tr>           
        }
    </table>
}
else
{
    @:<p>There are currently no Questions</p>
}
